package twel.probenprophet.profile.jaxb;

import java.io.Writer;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import twel.probenprophet.base.exceptions.ProbenprophetException;
import twel.probenprophet.base.interfaces.JaxbRootElement;

public class JaxbXmlWriter {

	public void writeXml(JaxbRootElement rootElement, Writer writer) {
		try {
			JAXBContext context = JAXBContext.newInstance(rootElement.getClass());
			Marshaller marshaller = context.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
			// marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
			marshaller.marshal(rootElement, writer);
		} catch (JAXBException e) {
			throw new ProbenprophetException("JAXB marshalling failed", e);
		}
	}
}
